<template>
  <div id="main">
    <div class="title">{{ title }}</div>
    <div class="my-table">
      <el-table
        :data="tableData"
        style="width: 100%"
        :row-style="iRowStyle"
        :cell-style="iCellStyle"
        :header-row-style="iHeaderRowStyle"
        :header-cell-style="iHeaderCellStyle"
        @row-click="handleRow"
      >
        <el-table-column prop="name" label="站点"> </el-table-column>
        <el-table-column prop="check" label="检测总数"> </el-table-column>
        <el-table-column prop="overload" label="超重总数"> </el-table-column>
        <el-table-column label="超重百分比">
          <template slot-scope="scope"> {{ scope.row.overweightPercent }}% </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Ranking',
  props: {
    tableData: {
      type: Array,
      default: function () {
        return []
      }
    },
    title: {
      type: String,
      default: '标题'
    }
  },
  methods: {
    iRowStyle({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return {
          height: '28px',
          fontSize: '14px',
          color: '#B1B3BE',
          backgroundColor: '#111441'
        }
      } else {
        return {
          height: '28px',
          fontSize: '14px',
          color: '#B1B3BE',
          backgroundColor: '#172257'
        }
      }
    },
    iHeaderRowStyle({ row, rowIndex }) {
      return {
        height: '28px'
      }
    },
    iCellStyle({ row, column, rowIndex, columnIndex }) {
      return {
        padding: '0px',
        textAlign: 'center',
        cursor: 'pointer'
      }
    },
    iHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
      return {
        color: '#4675C2',
        fontSize: '14px',
        backgroundColor: '#172257',
        padding: '0px',
        textAlign: 'center'
      }
    },
    handleRow(row, column, event) {
      this.$emit('click-row', row)
    }
  }
}
</script>

<style lang="less" scoped>
#main {
  padding: 15px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  .title {
    margin-bottom: 5px;
  }
  .my-table {
    height: 225px;
    overflow: hidden;
  }
}

.el-table {
  ::v-deep .cell {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  &::before {
    height: 0px;
  }
}

.customer-table .el-table__fixed-right::before,
.el-table__fixed::before {
  width: 0;
}
</style>
